using System.Collections.Generic;

namespace OffsetPath
{
    public class ClassM : LinkedList<PuntoDueD>
    {
        private const int a = 5;
        private const int b = 10;

        public void MethodA()
        {
            if (base.Count >= 2)
            {
                bool flag = true;
                int num = 0;
                while (flag && (num < 5))
                {
                    num++;
                    LinkedListNode<PuntoDueD> next = base.First.Next;
                    LinkedListNode<PuntoDueD> last = base.Last;
                    flag = false;
                    while (next != last)
                    {
                        LinkedListNode<PuntoDueD> previous;
                        LinkedListNode<PuntoDueD> node4;
                        LinkedListNode<PuntoDueD> node5;
                        LinkedListNode<PuntoDueD> node = next;
                        node = node.Previous;
                        int num2 = 1;
                        bool flag2 = false;
                        while ((num2 < 10) && (node != base.First))
                        {
                            previous = next;
                            previous = previous.Previous;
                            node4 = next;
                            node4 = node4.Next;
                            node5 = node;
                            node5 = node5.Previous;
                            double num3 = (previous.Value.MethodC(next.Value) + next.Value.MethodC(node4.Value)) + node5.Value.MethodC(node.Value);
                            double num4 = (previous.Value.MethodC(node4.Value) + node5.Value.MethodC(next.Value)) + next.Value.MethodC(node.Value);
                            if (num4 < num3)
                            {
                                PuntoDueD puntoDueD = next.Value;
                                base.Remove(next);
                                base.AddBefore(node, puntoDueD);
                                flag2 = true;
                                next = node4;
                                break;
                            }
                            node = node.Previous;
                            num2++;
                        }
                        int num5 = 2;
                        node = next;
                        node = node.Next;
                        if (node != null)
                        {
                            node = node.Next;
                        }
                        else
                        {
                            num5 = 10;
                        }
                        while ((!flag2 && (num5 < 10)) && (node != null))
                        {
                            previous = next;
                            previous = previous.Previous;
                            node4 = next;
                            node4 = node4.Next;
                            node5 = node;
                            node5 = node5.Previous;
                            double num6 = (previous.Value.MethodC(next.Value) + next.Value.MethodC(node4.Value)) + node5.Value.MethodC(node.Value);
                            double num7 = (previous.Value.MethodC(node4.Value) + node5.Value.MethodC(next.Value)) + next.Value.MethodC(node.Value);
                            if (num7 < num6)
                            {
                                PuntoDueD x2 = next.Value;
                                base.Remove(next);
                                base.AddBefore(node, x2);
                                next = node4;
                                flag2 = true;
                                break;
                            }
                            node = node.Next;
                            num5++;
                        }
                        if (flag2)
                        {
                            flag = true;
                        }
                        if (!flag2)
                        {
                            next = next.Next;
                        }
                    }
                }
            }
        }

        public void MethodA(List<PuntoDueD> A_0)
        {
            base.Clear();
            for (int i = 0; i < A_0.Count; i++)
            {
                base.AddLast(A_0[i]);
            }
            A_0.Clear();
        }

        public void MethodA(PuntoDueD A_0)
        {
            if (base.Count < 2)
            {
                if (base.Count == 1)
                {
                    base.AddLast(A_0);
                }
            }
            else
            {
                PuntoDueD puntoDueD = base.First.Value;
                PuntoDueD x2 = base.First.Next.Value;
                LinkedListNode<PuntoDueD> next = base.First.Next;
                LinkedListNode<PuntoDueD> node2 = base.First.Next;
                double num = (puntoDueD.MethodC(A_0) + A_0.MethodC(x2)) - puntoDueD.MethodC(x2);
                for (node2 = node2.Next; node2 != null; node2 = node2.Next)
                {
                    puntoDueD = x2;
                    x2 = node2.Value;
                    double num2 = (puntoDueD.MethodC(A_0) + A_0.MethodC(x2)) - puntoDueD.MethodC(x2);
                    if (num2 < num)
                    {
                        num = num2;
                        next = node2;
                    }
                }
                base.AddBefore(next, A_0);
            }
        }

        public void MethodB()
        {
            int count = base.Count;
            if (count >= 4)
            {
                LinkedListNode<PuntoDueD> first = base.First;
                int num2 = 0;
                int num3 = count - 3;
                bool flag = true;
                int num4 = 0;
                while (flag && (num4 < 5))
                {
                    num4++;
                    flag = false;
                    while (num2 < num3)
                    {
                        LinkedListNode<PuntoDueD> node = first;
                        node = node.Next;
                        LinkedListNode<PuntoDueD> next = first;
                        next = next.Next.Next;
                        LinkedListNode<PuntoDueD> node4 = first;
                        node4 = node4.Next.Next.Next;
                        double num5 = (first.Value.MethodC(node.Value) + node.Value.MethodC(next.Value)) + next.Value.MethodC(node4.Value);
                        double num6 = (first.Value.MethodC(next.Value) + next.Value.MethodC(node.Value)) + node.Value.MethodC(node4.Value);
                        if (num5 > num6)
                        {
                            PuntoDueD puntoDueD = next.Value;
                            base.Remove(next);
                            base.AddBefore(node, puntoDueD);
                            flag = true;
                        }
                        first = first.Next;
                        num2++;
                    }
                }
            }
        }

        public void MethodB(List<PuntoDueD> A_0)
        {
            for (LinkedListNode<PuntoDueD> node = base.First; node != null; node = node.Next)
            {
                A_0.Add(node.Value);
            }
            base.Clear();
        }

        public void c()
        {
            if (base.Count >= 4)
            {
                PuntoDueD puntoDueD = base.First.Value;
                base.RemoveFirst();
                PuntoDueD x2 = base.Last.Value;
                base.RemoveLast();
                ClassAq classAq = new ClassAq();
                this.MethodB(classAq);
                base.AddFirst(puntoDueD);
                base.AddLast(x2);
                classAq.c(puntoDueD.MethodA(x2));
                classAq.Reverse();
                while (classAq.Count > 0)
                {
                    this.MethodA(classAq[classAq.Count - 1]);
                    classAq.RemoveAt(classAq.Count - 1);
                }
            }
        }

        public void d()
        {
            if (base.Count >= 2)
            {
                LinkedListNode<PuntoDueD> next = base.First.Next;
                LinkedListNode<PuntoDueD> last = base.Last;
                while (next != last)
                {
                    LinkedListNode<PuntoDueD> node = base.First.Next;
                    while (node != null)
                    {
                        if (node == next)
                        {
                            node = node.Next;
                        }
                        else
                        {
                            LinkedListNode<PuntoDueD> previous = next;
                            previous = previous.Previous;
                            LinkedListNode<PuntoDueD> node5 = next;
                            node5 = node5.Next;
                            LinkedListNode<PuntoDueD> node6 = node;
                            node6 = node6.Previous;
                            double num = (previous.Value.MethodC(next.Value) + next.Value.MethodC(node5.Value)) + node6.Value.MethodC(node.Value);
                            double num2 = (previous.Value.MethodC(node5.Value) + node6.Value.MethodC(next.Value)) + next.Value.MethodC(node.Value);
                            if (num2 < num)
                            {
                                PuntoDueD puntoDueD = next.Value;
                                base.Remove(next);
                                base.AddBefore(node, puntoDueD);
                                break;
                            }
                            node = node.Next;
                        }
                    }
                    next = next.Next;
                }
            }
        }

        ~ClassM()
        {
        }
    }
}

